﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Model;
using BLL;
namespace UI
{
    public partial class 商品消费查询 : Form
    {
        public 商品消费查询()
        {
            InitializeComponent();
        }
        //全局变量
        Model_ConsumerBill_Tables_ConsumerDetail_Vips m = new Model_ConsumerBill_Tables_ConsumerDetail_Vips();

        Model_ConsumerBill_Tables_ConsumerDetail_Vips m2 = new Model_ConsumerBill_Tables_ConsumerDetail_Vips();
        public void XiaoFei(Model_ConsumerBill_Tables_ConsumerDetail_Vips m)
        {
            this.listView1.Items.Clear();
            //执行操作
            SqlDataReader dr = 商品消费查询BLL.Query(m); ;
            //打开阅读器
            while (dr.Read())
            {
                ListViewItem li = new ListViewItem(dr[0].ToString());
                for (int i = 1; i < 8; i++)
                {
                    li.SubItems.Add(dr[i].ToString());
                }
                this.listView1.Items.Add(li);
            }
            //关闭
            dr.Close();

        }
        public void TianjianQuery(Model_ConsumerBill_Tables_ConsumerDetail_Vips m)
        {
            this.listView1.Items.Clear();
            //执行操作
            SqlDataReader dr = 商品消费查询BLL.Query2(m);
            //打开阅读器
            while (dr.Read())
            {
                ListViewItem li = new ListViewItem(dr[0].ToString());
                for (int i = 1; i < 8; i++)
                {
                    li.SubItems.Add(dr[i].ToString());
                }
                this.listView1.Items.Add(li);
            }
            //关闭
            dr.Close();

        }

        private void 商品消费查询_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("全部");
            comboBox1.Items.Add("按餐台号查询");
            comboBox1.Items.Add("按消费项目查询");
            textBox1.Enabled = false;
            button1.ContextMenuStrip = contextMenuStrip1;
            XiaoFei(m2);
        }

        private void 今天ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " 00:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day + 1) + " 00:00:00.000";
            //调用方法
            XiaoFei(m);
        }

        private void 昨天ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day - 1) + " 00:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " 00:00:00.000";
            //调用方法
            XiaoFei(m);
        }

        private void 前天ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day - 2) + " 00:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day - 1) + " 00:00:00.000";
            //调用方法
            XiaoFei(m);
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now; //当前时间
            //当前时间
            m.CBEndDate = dt.Year + "-" + dt.Month + "-" + (dt.Day + 1) + " 00:00:00.000";
            //获取当前星期几
            string weekName = dt.DayOfWeek.ToString();
            switch (weekName)
            {
                case "Sunday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 6) + " 00:00:00.000";
                    break;
                case "Monday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + dt.Day + " 00:00:00.000";
                    break;
                case "Tuesday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 1) + " 00:00:00.000";
                    break;
                case "Wednesday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 2) + " 00:00:00.000";
                    break;
                case "Thursday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 3) + " 00:00:00.000";
                    break;
                case "Friday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 4) + " 00:00:00.000";
                    break;
                case "Saturday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 5) + " 00:00:00.000";
                    break;
            }
            XiaoFei(m);
        }

        private void 本月ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-01 01:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + (DateTime.Now.Month + 1) + "-01 01:00:00.000";
            //调用方法
            XiaoFei(m);
        }

        private void 上月ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + (DateTime.Now.Month - 1) + "-01 01:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-01 01:00:00.000";
            //调用方法
            XiaoFei(m);

        }

        private void 所有时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            XiaoFei(m2);
        }

        private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            textBox1.Enabled = true;
            if (comboBox1.SelectedIndex == 0)
            {
                textBox1.Enabled = false;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 1)
            {
                if (textBox1.Text =="")
                {
                    textBox1.Focus();
                    return;
                }
                m.TableName = "1";
                m.ProductName = textBox1.Text;
                TianjianQuery(m);
            }
            else if (comboBox1 .SelectedIndex == 2)
            {
                if (textBox1.Text == "")
                {
                    textBox1.Focus();
                    return;
                }
                m.TableName = "2";
                m.ProductName = textBox1.Text;
                TianjianQuery(m);
            }
            else
            {
                textBox1.Enabled = false;
                XiaoFei(m2);
            }
        }

        private void dateTimePicker1_ValueChanged_1(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = this.dateTimePicker1.Value.ToString();
            m.CBEndDate = this.dateTimePicker2.Value.ToString();
            XiaoFei(m);
        }

        private void dateTimePicker2_ValueChanged_1(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = this.dateTimePicker1.Value.ToString();
            m.CBEndDate = this.dateTimePicker2.Value.ToString();
            XiaoFei(m);
        }

        private void 昨天ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day - 1) + " 00:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " 00:00:00.000";
            //调用方法
            XiaoFei(m);
        }

        private void 前天ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day - 2) + " 00:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day - 1) + " 00:00:00.000";
            //调用方法
            XiaoFei(m);
        }
    }
}